﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_HealthTherapyDetailSrhForm
 * 类型：       控制层
 * 功能说明：   健康管家-治疗信息列表页面
 * 作者：       章 昕
 * 创建日期：   2007/09/13
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Bean;
using Shpm.App.Input.Dao;
using log4net;
using Shpm.System;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Commons.Utils;

public partial class App_Input_HealthTherapyDetailSrhForm : System.Web.UI.Page
{
    // log
    protected static ILog log = LogManager.GetLogger(typeof(App_Input_HealthTherapyDetailSrhForm));

    // gridview 完成情况列
    private const int COLUMN_CUREDFLG = 3;

    // page load
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // 取得当前登录的医生id信息
            SysUserManager manager = new SysUserManager(Context);
            SysUserBean sysUserBean = manager.getSysUserBean();
            MstSysUserBean mstSysUserBean =
                sysUserBean == null ? null : sysUserBean.getMstSysUserBean();
            MstEmployeeBean mstEmpBean =
                sysUserBean == null ? null : sysUserBean.getEmployeeBean();
            string loginId = mstSysUserBean == null ? "" : mstSysUserBean.SysUserId;
            string emplyId = mstSysUserBean == null ? "" : mstSysUserBean.EmployeeId;
            //string emplyRole = mstEmpBean == null ? "" : mstEmpBean.Role;
            ViewState["DOCTOR_ID"] = emplyId;
            ViewState["CURE_ID"] = Convert.ToString(Context.Items["CURE_ID"]);

            if (Context.Items.Contains("ParamPageIndex"))
            {
                ViewState["ParamPageIndex"] = Context.Items["ParamPageIndex"];
            }

            if (Context.Items.Contains("MemberNo"))
            {
                this.ViewState["MemberNo"] = Convert.ToString(Context.Items["MemberNo"]);
            }
            if (Context.Items.Contains("Sex"))
            {
                this.ViewState["Sex"] = Convert.ToString(Context.Items["Sex"]);
            }
            if (Context.Items.Contains("BuildingNo"))
            {
                this.ViewState["BuildingNo"] = Convert.ToString(Context.Items["BuildingNo"]);

            }
            if (Context.Items.Contains("FloorNo"))
            {
                this.ViewState["FloorNo"] = Convert.ToString(Context.Items["FloorNo"]);
            }
            if (Context.Items.Contains("Room"))
            {
                this.ViewState["Room"] = Convert.ToString(Context.Items["Room"]);
            }
        }
    }

    // before render
    void Page_PreRender(object sender, EventArgs e)
    {
        // get current doctor responsibility members list
        HealthTherapyDao dao = new HealthTherapyDao();
        IList lstRst = null;
        HealthTherapyDetailBean beanHTD = new HealthTherapyDetailBean();        
        beanHTD.CureId = Convert.ToInt32(ViewState["CURE_ID"]);
        lstRst = dao.ListMemberCureDetail(beanHTD);
        viewSrhRst.DataSource = lstRst;
        viewSrhRst.DataBind();
        if (lstRst != null && lstRst.Count > 0)
        {
            beanHTD = (HealthTherapyDetailBean)lstRst[0];
            lblMemSex.Text = beanHTD.MemberSex;
            lblMemId.Text = beanHTD.MemberNo;
            lblMemName.Text = beanHTD.MemberName;
            lblMemTel.Text = beanHTD.MemberTel;
            lblRoomNo.Text = beanHTD.ApartmentNo;
            lblDocId.Text = beanHTD.DoctorId;
        }
    }

    // page index change
    protected void viewSrhRst_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 设置分页编号
        viewSrhRst.PageIndex = e.NewPageIndex;
    }

    // details click
    protected void viewSrhRst_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (Request["x"] == null || Request["y"] == null)
            return;

        string rowId = "";
        string url = "~/App/Input/HealthTherapyDetailSrhForm.aspx";       
        if (e.CommandName == "Details")
        {
            int index = Convert.ToInt32(e.CommandArgument);
            // Get the Key value from the GridView control.
            DataKey key = viewSrhRst.DataKeys[index];
            rowId = Convert.ToString(key.Value);
            url = "~/App/Input/HealthTherapyDetailUpdForm.aspx";
        }

        // 传递分页编号
        Context.Items["ROW_ID"] = rowId;
        Context.Items["CURE_ID"] = ViewState["CURE_ID"];
        Context.Items["ParamPageIndex"] = viewSrhRst.PageIndex;
        //Response.Redirect("~/App/Input/HealthTherapyUpdForm.aspx?CURE_ID=" + cureId);
        ControllerUtils.Transfer(Context, url, true);

    }

    // adjust bind data
    protected void viewSrhRst_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // has got a plan detail 
            e.Row.Cells[COLUMN_CUREDFLG].Text = "预约";
            if (Convert.ToBoolean(((HealthTherapyDetailBean)e.Row.DataItem).CureFlg))
            {
                e.Row.Cells[COLUMN_CUREDFLG].Text = "完成";
            }
        }
    }

    // 返回按钮
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string url = "~/App/Input/HealthTherapySrhForm.aspx";
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];
        Context.Items["MemberNo"] = ViewState["MemberNo"];
        Context.Items["Sex"] = ViewState["Sex"];
        Context.Items["BuildingNo"] = ViewState["BuildingNo"];
        Context.Items["FloorNo"] = ViewState["FloorNo"];
        Context.Items["Room"] = ViewState["Room"];
        ControllerUtils.Transfer(Context, url, true);    
    }

}
